//web端
export function dellReportInfo(
  data,
  selectImgs,
  user,
  hospital,
  linkUser,
  linkHospital
) {
  let patient_user_info = data.patient_user_info
    ? JSON.parse(data.patient_user_info)
    : {
        user: {
          name: user.name,
          logo: user.sign,
        },
        hospital: {
          name: hospital.name,
          logo: hospital.logo,
        },
      };
  let doctor_user_info = data.doctor_user_info
    ? JSON.parse(data.doctor_user_info)
    : {
        user: {
          name: linkUser ? linkUser.name : "",
          logo: linkUser ? linkUser.sign : "",
        },
        hospital: {
          name: linkHospital ? linkHospital.name : "",
          logo: linkHospital ? linkHospital.logo : "",
        },
      };
  let report_user_info = data.report_user_info
    ? JSON.parse(data.report_user_info)
    : {
        user: {
          name: user.name,
          logo: user.sign,
        },
        hospital: {
          name: hospital.name,
          logo: hospital.logo,
        },
      };
  if (!patient_user_info.hospital) {
    patient_user_info.hospital = {
      name: hospital.name,
      logo: hospital.logo,
    };
  }
  if (!doctor_user_info.hospital) {
    doctor_user_info.hospital = {
      name: linkHospital ? linkHospital.name : "",
      logo: linkHospital ? linkHospital.logo : "",
    };
  }
  if (!report_user_info.hospital) {
    report_user_info.hospital = {
      name: hospital.name,
      logo: hospital.logo,
    };
  }
  if (data.state === 4 || data.state === 6) {
    //已出报告
    let images = data.choseImg
      ? JSON.parse(data.reportimg).filter((item) => {
          return JSON.parse(data.choseImg).includes(item.param_id);
        })
      : [];
    return {
      ...data,
      patient_user_info,
      doctor_user_info,
      report_user_info,
      images: images,
      seen: getReportSeen(data.seen, data.seenData),
      tips: data.tips
        ? data.tips.replace(/\n/g, "<br/>&ensp;&ensp;&ensp;&nbsp;")
        : "",
    };
  } else {
    //还未出报告
    return {
      ...data,
      images: selectImgs,
      patient_user_info,
      doctor_user_info,
      report_user_info,
      seen: getReportSeen(data.seen, data.seenData),
      tips: data.tips
        ? data.tips.replace(/\n/g, "<br/>&ensp;&ensp;&ensp;&nbsp;")
        : "",
    };
  }
}
//web端
export function dellHospitalInfo(data, user, hospital, linkUser, linkHospital) {
  if (data.patient_user_info && data.doctor_user_info) {
    const patient_user_info = JSON.parse(data.patient_user_info);
    const doctor_user_info = JSON.parse(data.doctor_user_info);
    const new_hospitalInfo = {
      userInfo: { name: doctor_user_info.user.name },
      curDocHospital: { name: doctor_user_info.hospital.name },
      docLinkPatUser: { name: patient_user_info.user.name },
      docLinkPatHos: { name: patient_user_info.hospital.name },
    };
    return new_hospitalInfo;
  } else if (data.patient_user_info && !data.doctor_user_info) {
    const patient_user_info = JSON.parse(data.patient_user_info);
    const new_hospitalInfo = {
      userInfo: {
        name: linkUser ? linkUser.name : "",
      },
      curDocHospital: {
        name: linkHospital ? linkHospital.name : "",
      },
      docLinkPatUser: { name: patient_user_info.user.name },
      docLinkPatHos: { name: patient_user_info.hospital.name },
    };
    return new_hospitalInfo;
  } else if (!data.patient_user_info && data.doctor_user_info) {
    const doctor_user_info = JSON.parse(data.doctor_user_info);
    const new_hospitalInfo = {
      userInfo: { name: doctor_user_info.user.name },
      curDocHospital: { name: doctor_user_info.hospital.name },
      docLinkPatUser: { name: user.name },
      docLinkPatHos: { name: hospital.name },
    };
    return new_hospitalInfo;
  } else {
    let hospitalInfo = {
      userInfo: { name: "" },
      curDocHospital: { name: "" },
      docLinkPatUser: { name: "" },
      docLinkPatHos: { name: "" },
    };
    if (linkUser) {
      hospitalInfo.userInfo = linkUser;
    }
    if (linkHospital) {
      hospitalInfo.curDocHospital = linkHospital;
    }
    if (user) {
      hospitalInfo.docLinkPatUser = user;
    }
    if (hospital) {
      hospitalInfo.docLinkPatHos = hospital;
    }
    return hospitalInfo;
  }
}

export function getReportSeen(seen, seenData) {
  if (seen) {
    seenData = Array.isArray(seenData)
      ? seenData
      : seenData
      ? JSON.parse(seenData)
      : "";
    let show = seen.split("_");
    let list = [];
    show.forEach((el) => {
      list.push(el);
      list.push("");
    });
    list.pop();
    if (seenData.length !== 0) {
      seenData.forEach((el, index) => {
        list[index * 2 + 1] = el.toString();
      });
    }
    list = list.join("");
    list = list.replace(/\n/g, "<br/>&ensp;&ensp;&ensp;&nbsp;");
    return list;
  } else {
    return "";
  }
}
